<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%String path = request.getContextPath() ;%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div>
		<div class="searchArea">
			<!-- 搜索表单开始 -->
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					<div class="FXBR">
						<div class="fieldBox">
							<div class="label">集团公司名称</div>
							<div class="field">
								<input type="text"  name="name" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						
						
					</div>
					<div class="clearFix"></div>
					
					<div class="btnsBox formBtns notRight">
						<span id="searchBtn" class="sq-button-round">查询</span>
						<span id="clearBtn" class="sq-button-round">清空</span>
						
						<sys:funcAuth resCd="fncGroupCompany_add">
							<span id="add" class="sq-button-round">新增集团公司</span>
						</sys:funcAuth>
						<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
		            </div>
		           
				</div>
			</form>
			<!-- 搜索表单结束 -->
		</div>
		<!-- 列表显示块 -->
		<div id="ligergrid1" class="sq-grid"></div>

</div>
</div>


<!-- 新增集团公司页面 -->
<div id="addHtml" style="display:none">
    <form id="addForm">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100">
                <div class="label">集团公司名称</div>
                <div class="field">
                    <input id="addFormName" name="name"  type="text" class="ui-textbox"  validate="{required:true}" />
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
        <div class="btnsBox">
            <span id="save" class="sq-button sq-button-hasicon"><i class="sqBtnIco_10"></i>保存</span>
        </div>
        </div>
    </form>
</div>

<script type="text/javascript">
	var grid = null;
	var updateId = null;
	$(function () {
		$("#searchBar").ligerForm();
		$("#addForm").ligerForm({validate: true});
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件
	});
	
	//新增集团公司页面
	 $("#add").click(function(event) {
		 updateId = null;
		 clearLigerForm("addForm");
		 addLigerDialog('新增集团公司');
	 });
	
	//修改集团公司页面
	 function update(id){
		 updateId = id;
		 $.ajax({
			type: 'get',
			dataType:'json',
			url: '<%=path%>/account/fncGroupCompany/selectById.do?id='+id,
			success:function(data){
				if(data){
					//设置数据
					$("#addFormName").val(data.name);
					//展示页面
					//clearLigerForm("addForm");
					addLigerDialog('修改集团公司');
				}else{
					 $.ligerDialog.SQalert({content:"没有查询到信息", SQ_type: "error"});
				}
			}
		});
	 }
	
	function addLigerDialog(_title){
		
		 $.ligerDialog.open({
	            width: 400,
	            title : _title,
	            target: $("#addHtml"),
	            onHideDialog: function () {
	            }
	      });
		 
	}
	 
	//新增修改集团公司保存 
	 $("#save").click(function(event) {
	        var form = liger.get("addForm");
	         if (!form.valid()) {
	        	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
	            return false; 
	        } 
	        var data = form.getData();
	         if(data) {
		        data["id"] =updateId;
	        }
	         console.log(data);
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:data,
				url: '<%=path%>/account/fncGroupCompany/save.do',
				beforeSend:function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.hide();
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
	    });
	
	
	 function del(id){
		 
		 $.ligerDialog.confirm("确认要删除该集团公司吗?(该集团下的账户也会被清除，请谨慎操作)", function (flag) {
			 if(!flag) return;
			 var wait_dialog = null;
			 $.ajax({
				type: 'get',
				dataType:'json',
				url: '<%=path%>/account/fncGroupCompany/removeById.do?id='+id,
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
				},success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				},error:function (XMLHttpRequest, textStatus, errorThrown) { 
					wait_dialog.close();
					$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
				}
			});
		 });
	 }
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/account/fncGroupCompany/initList.do',
			method:'get',
			parms:getSearchParams(),
			columns:[
				{ display: '集团公司名称', 
					render:function (rowdata, rowindex, value){
						return "<span title="+rowdata.name+">"+rowdata.name+"</span>";
					}
				},
				{ display: '一般存款账户', name: 'accountNum1', 
					render:function (rowdata, rowindex, value){
						if(rowdata.accountNum1) {
							return rowdata.accountNum1;
						}else {
							return 0;
						}
					}
				},
				{ display: '基本存款账户', name: 'accountNum2', 
					render:function (rowdata, rowindex, value){
						if(rowdata.accountNum2) {
							return rowdata.accountNum2;
						}else {
							return 0;
						}
					}
				},
				{ display: '临时存款账户', name: 'accountNum3', 
					render:function (rowdata, rowindex, value){
						if(rowdata.accountNum3) {
							return rowdata.accountNum3;
						}else {
							return 0;
						}
					}
				},
				{ display: '专用存款账户', name: 'accountNum4' , 
					render:function (rowdata, rowindex, value){
						if(rowdata.accountNum4) {
							return rowdata.accountNum4;
						}else {
							return 0;
						}
					}
				},
				{ display: '账户总数', name: 'accountNumAll', 
					render:function (rowdata, rowindex, value){
						var accountNumAll = 0;
						if(rowdata.accountNum1) {
							accountNumAll += rowdata.accountNum1;
						}
						if(rowdata.accountNum2) {
							accountNumAll += rowdata.accountNum2;
						}
						if(rowdata.accountNum3) {
							accountNumAll += rowdata.accountNum3;
						}
						if(rowdata.accountNum4) {
							accountNumAll += rowdata.accountNum4;
						}
							
						return accountNumAll;
					} 
				},
				{
					display:'操作',
					width:220,
					render:function (rowdata, rowindex, value){
						var h="";
						
						<sys:funcAuth resCd="fncGroupCompany_update">
							h+='<a class="sq-button-hasicon" href="javascript:update(';
			            	h+="'"+rowdata.id+"',";
			                h+=")\"><i class='sqBtnIco_4'></i>修改</a>";
						</sys:funcAuth>
					
						<sys:funcAuth resCd="fncGroupCompany_del">
			                h+='<a class="sq-button-hasicon" href="javascript:del(';
			            	h+="'"+rowdata.id+"',";
			                h+=")\"><i class='sqBtnIco_4'></i>删除</a>";
			            </sys:funcAuth>
		                
						return h;
					}
				},
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			isScroll: true,
			checkbox:true,//列表是否有选择框
			rownumbers:true,//列表是否有行号
			
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
	}
	
	
	//查看详情
	function viewDetail(paySchId,contractNo){
		
		var param = '<%=path%>/archive/arcBorrowMain/viewDetail.do?paySchId=' + paySchId+'&contractNo='+contractNo ;
		Add_navTab('arcBorrowMainViewDetail'+paySchId,'查看详情',param, function () {
			grid.reload();
		});
	}
	
	
	
	//清空按钮事件
	function clearBtnEvent(){
		$("#clearBtn").click(function(event) {
			$("#resetBtn").click();  //重置 input-text
			/*var form = liger.get("searchBar");
			 form.setData({  //重置select等特殊表单
				"buOrgCd":"",
				"eleStorageStatus":"",
				"cstMgrOrgCd":"",
				"storageStatus":""
			}); */
			//liger.get('cstMgrOrgCd').clear();
			//searchOrgTree.clear();
		});
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		$("#searchBtn").click(function(event) {
			var form = new liger.get("searchBar");
			var data = form.getData();
			//alert(JSON.stringify(data));
			for (name in data){
				grid.setParm(name,data[name]);
			};
			grid.reload();
		});
	}
	
	
	
	
	
</script>
</body>
</html>